package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import factory.DAOFactory;

/**
 * Servlet implementation class DeleteAdServlet
 */
@WebServlet("/DeleteAdServlet")
public class DeleteAdServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteAdServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int id = Integer.parseInt(request.getParameter("id"));
		if(DAOFactory.getAdDAOInstance().delete(id)>0) {
			response.setContentType("text/html; charset=UTF-8");
			response.getWriter().println("<script LANGUAGE='javascript'> alert('删除成功！');</script>");
			response.sendRedirect("store_ad.jsp");
		} else {
			response.setContentType("text/html; charset=UTF-8");
			response.getWriter().println("<script LANGUAGE='javascript'> alert('删除失败！');history.go(-1);</script>");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
